package com.sljy.hzk.ui.detection;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.sljy.hzk.R;
import com.sljy.hzk.annotation.ActivityInfo;
import com.sljy.hzk.base.BaseActivity;
import com.sljy.hzk.view.CustomStateText;
import com.tkk.api.RxEventProcessor;
import com.tkk.api.annotation.Recipient;
import com.unnamed.b.atv.model.TreeNode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@ActivityInfo(layout = R.layout.activity_add_detection,isShowActionBar = true, title = "危害因素采集", titleLevel = ActivityInfo.TITLE_TWO_LEVEL)
public class AddDetectionActivity extends BaseActivity {

    int pId = -1;
    String pName,allName;
    @BindView(R.id.edit_name)
    EditText editName;
    @BindView(R.id.tv_chose_partition)
    TextView tvChosePartition;
    @BindView(R.id.tv_start)
    ImageButton tvStart;

    @Override
    protected void init() {
        RxEventProcessor.get().bind(this);
    }

    @OnClick(R.id.tv_chose_partition)
    public void onViewClicked() {
        startActivity(ChosePartitionActivity.class);
    }

    @Recipient(tag = "chose_finish")
    public void onChoseFinish(int pId,String pName,String allName) {
        this.pId = pId;
        tvChosePartition.setText(allName);
        //tvPartitionInfo.setText(allName);
    }

    @OnClick(R.id.tv_start)
    public void onStartViewClicked() {
        String name = editName.getText().toString();
        if (TextUtils.isEmpty(name)){
            showToast("请输入记录名称");
            return;
        }
        if (pId == -1){
            showToast("请选择分区");
            return;
        }
        DetectionFillInActivity__JumpCenter
                .builder(this)
                .setPId(pId)
                .setPosName(tvChosePartition.getText().toString())
                .setRecordName(name)
                .setIsFromLocal(false)
                .create().go();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RxEventProcessor.get().unBind(this);

    }
}
